function a(){
    this.host='http://'+window.location.hostname+':'+window.location.port
    this.fetchtemplate=async function(path,method='GET',data=null){
        let url=this.host
        if(path.startsWith('/api/admin')){
            url='http://'+window.location.hostname+':5001'
        }
        let headersData={'method':method,'headers':{}}
        method!='GET' && data!=null?headersData['body']=JSON.stringify(data):"";
        method!='GET'?headersData['headers']={}:"";
    
        method!='GET'?headersData['headers']['content-type']='application/json':"";
        response=await fetch(url+path,headersData)

        return await response.json()
    }
}
async function rendertable(data,domhtml,domdata){
    let html=''
   for (const i of data){
       html+='<tr>'
       for (const key of domdata){
           html+=`<td>${i[key]}</td>`
       }
       html+='</tr>'
   }
  
   $(domhtml).html(html)
}

taskObject=new a();
taskObject.layerErrorView=function (message){
        layer.msg(message, {icon: 2, time: 3000});
}
taskObject.layerSuccessView=function(message){
        layer.msg(message, {icon: 1, time: 3000});
}
$('#loginout').click(async ()=>{
    response=await taskObject.fetchtemplate('/logout')
    setTimeout(()=>{
        taskObject.layerSuccessView('退出登录成功')
    },1000)
    setTimeout(()=>{
        window.location.href='./login'
    },1500)
})